package com.gsdse.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsdse.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDao extends BaseMapper<User> {

    @Select("select user.userId,user.applyId,user.phoneNumber,user.userName,user.schoolClass,user.email,user.positionName,user.position,user.wxuserId,user.departmentId,wxuser.avatarUrl,wxuser.nickName from user,wxuser where user.userId = #{userId} and user.userId = wxuser.userId")
    User selectUserByUserId(Integer userId);

    @Select("select email from user where userId = #{userId}")
    String selectEmailByUserId(Integer userId);

    @Update("update user set applyId=#{applyId},phoneNumber=#{phoneNumber},userName=#{userName}," +
            "schoolClass=#{schoolClass},email=#{email},positionName=#{positionName}," +
            "position=#{position}, wxuserId=#{wxuserId}, departmentId=#{departmentId} where userId=#{userId}")
    Boolean updateUserById(User user);

    @Insert("insert into user values (#{userId},#{applyId},#{phoneNumber},#{userName},#{schoolClass}," +
            "#{email},#{positionName},#{position},  #{wxuserId}, #{departmentId})")
    Boolean InsertUser(User user);

    @Select("select * from user where  userName=#{userName} and phoneNumber=#{phoneNumber}")
    User selectUserByReallyNameAndPhoneNumber(@Param("userName")String userName,@Param("phoneNumber") String phoneNumber);

    @Select("select * from user where  userName=#{userName} and email=#{email}")
    User selectUserByReallyNameAndEmail(@Param("userName")String ReallyName,@Param("email") String email);


    @Update("update user,wxuser set user.applyId=#{applyId},user.phoneNumber=#{phoneNumber},user.userName=#{userName}," +
            "user.schoolClass=#{schoolClass},user.email=#{email},user.positionName=#{positionName}," +
            "user.position=#{position}, user.wxuserId=#{wxuserId}, user.departmentId=#{departmentId}, wxuser.avatarUrl=#{avatarUrl},wxuser.nickName=#{nickName} where wxuser.userId=#{userId} and user.userId=wxuser.userId")
    Boolean updateUserAndAvatarById(User user);

}
